﻿using System;
using RootMotion.FinalIK;
using UnityEngine;

namespace RootMotion.Demos
{
	// Token: 0x020000A1 RID: 161
	public class FBIKBoxing : MonoBehaviour
	{
		// Token: 0x06000561 RID: 1377 RVA: 0x00034C54 File Offset: 0x00032E54
		public float GetHitWeight()
		{
			this.info = this.animator.GetCurrentAnimatorStateInfo(0);
			if (this.info.IsName("Boxing"))
			{
				return this.unityFreeHitWeight.Evaluate(this.info.normalizedTime - (float)((int)this.info.normalizedTime));
			}
			return 0f;
		}

		// Token: 0x06000562 RID: 1378 RVA: 0x0000568E File Offset: 0x0000388E
		public void Start()
		{
			this.animator = base.GetComponent<Animator>();
			this.ik.enabled = false;
			if (this.aim != null)
			{
				this.aim.enabled = false;
			}
		}

		// Token: 0x06000563 RID: 1379 RVA: 0x00034CB4 File Offset: 0x00032EB4
		public void LateUpdate()
		{
			float hitWeight = this.GetHitWeight();
			this.ik.solver.GetEffector(this.effector).position = this.target.position;
			this.ik.solver.GetEffector(this.effector).positionWeight = hitWeight * this.weight;
			if (this.aim != null)
			{
				this.aim.solver.transform.LookAt(this.pin.position);
				this.aim.solver.IKPosition = this.target.position;
				this.aim.solver.IKPositionWeight = this.aimWeight.Evaluate(hitWeight) * this.weight;
				this.aim.solver.Update();
			}
			this.ik.solver.Update();
		}

		// Token: 0x04000443 RID: 1091
		[Tooltip("The target we want to hit")]
		public Transform target;

		// Token: 0x04000444 RID: 1092
		[Tooltip("The pin Transform is used to reference the exact hit point in the animation (used by AimIK to aim the upper body to follow the target).In Legacy and Generic modes you can just create and position a reference point in your animating software and include it in the FBX. Then in Unity if you added a GameObject with the exact same name under the character's root, it would be animated to the required position.In Humanoid mode however, Mecanim loses track of any Transform that does not belong to the avatar, so in this case the pin point has to be manually set inside the Unity Editor.")]
		public Transform pin;

		// Token: 0x04000445 RID: 1093
		[Tooltip("The Full Body Biped IK component")]
		public FullBodyBipedIK ik;

		// Token: 0x04000446 RID: 1094
		[Tooltip("The Aim IK component. Aim IK is ust used for following the target slightly with the body.")]
		public AimIK aim;

		// Token: 0x04000447 RID: 1095
		[Tooltip("The master weight")]
		public float weight;

		// Token: 0x04000448 RID: 1096
		[Tooltip("The effector type of the punching hand")]
		public FullBodyBipedEffector effector;

		// Token: 0x04000449 RID: 1097
		[Tooltip("Workaround for Unity Free users that don't have access to Mecanim curves")]
		public AnimationCurve unityFreeHitWeight;

		// Token: 0x0400044A RID: 1098
		[Tooltip("Weight of aiming the body to follow the target")]
		public AnimationCurve aimWeight;

		// Token: 0x0400044B RID: 1099
		public Animator animator;

		// Token: 0x0400044C RID: 1100
		public AnimatorStateInfo info;
	}
}
